
function disableAllTab(){
	document.getElementById('content_1').style.display='none';
	document.getElementById('content_2').style.display='none';
	document.getElementById('content_3').style.display='none';
	document.getElementById('content_4').style.display='none';
	document.getElementById('content_5').style.display='none';
}

function setBootstrapName(name){
	if(name.length > 1){
		name = name.toLowerCase();
		var arrChar = name.split("");
		var firsChar = arrChar[0].toUpperCase();
		moduleName = firsChar+name.substring(1);
		var bootstrapName = moduleName+"_Bootstrap";
		document.getElementById('bootstrap_name').innerHTML = bootstrapName;
		document.getElementById('bootstrapName').value = bootstrapName;
	}
}
function setControllerName(name){
	if(name.length > 1){
		name = name.toLowerCase();
		var arrChar = name.split("");
		var firsChar = arrChar[0].toUpperCase();
		name = firsChar+name.substring(1);
		var controllerName = moduleName+"_"+name+"Controller";
		document.getElementById('controllerName').innerHTML = controllerName;
		document.getElementById('denyTemplate-Controller1').innerHTML = name+"Controller" +'\n'+ '&nbsp;<input type="radio" name="" id="denyTemplate-Controller1-checkbox" value="'+name.toLowerCase()+'" />';
		document.getElementById('deny1-Controller1').innerHTML = name+"Controller" +'\n'+ '&nbsp;<input type="radio" name="deny[0][]" id="deny1-Controller1-checkbox" value="'+name.toLowerCase()+'" />';
		document.getElementById('defaultControllerHidden').value = name.toLowerCase();
		document.frmModuleSettup.controllerName.value = controllerName;
	}
}
function checkControllerName(name){
	
	var element = document.getElementById(name+'hidden');
	if (typeof(element) != 'undefined' && element != null)
	{
		alert(name+'Controller đã tồn tại, bạn phải chọn tên khác');
		document.getElementById('inputControllerName').focus();
	}
}
function checkModelName(name){
	var element = document.getElementById(name+'ModelHidden');
	if (typeof(element) != 'undefined' && element != null)
	{
		alert('Model '+name+' đã tồn tại, bạn phải chọn tên khác');
		document.getElementById('modelSingleName').focus();
	}
}
function setModelName(name){
	if(name.length > 1){
		name = name.toLowerCase();
		var arrChar = name.split("");
		var firsChar = arrChar[0].toUpperCase();
		name = firsChar+name.substring(1);
		var modelName = moduleName+"_Model_"+name;
		document.getElementById('modelName').innerHTML = modelName;
		document.frmModuleSettup.modelName.value = modelName;
	}
}
var STTCONTROLLER = 1;
var STTACTION = 1;
var STTFUNCTION = 1;
var STTPROPERTY = 1;
var STTVIEW = 1;
var STTDENY = 1;
function addController(){
	STTCONTROLLER++;
	var controllerNameId = document.getElementById('controllerNameTemp');        
	controllerNameId.setAttribute('id','controllerName'+STTCONTROLLER);
	var inputControllerName = document.getElementById('inputControllerNameTemp');        
	inputControllerName.setAttribute('id','inputControllerName'+STTCONTROLLER);
	inputControllerName.setAttribute('onkeyUp','setControllerName(this.value,'+STTCONTROLLER+')');
	
	var html = document.getElementById('controllerTemplate').innerHTML;
	
	var controllers = document.getElementById('controllers');
	var divController = document.createElement('div');
	divController.setAttribute('id','controller'+STTCONTROLLER);        
	divController.innerHTML = html;
	controllerNameId.setAttribute('id','controllerNameTemp');
	inputControllerName.setAttribute('id','inputControllerNameTemp');
	
	controllers.appendChild(divController);
}
function addAction(){
	STTACTION++;
	// get Property
	var actionNameTemplate = document.getElementById('actionNameTemplate');
	actionNameTemplate.setAttribute('id','actionName'+STTACTION);
	// create Element
	var template = document.getElementById('template-actions').innerHTML;
	var action_zone = document.getElementById('actions');
	var divAction = document.createElement('div');
	divAction.setAttribute('id','action'+STTACTION);
	divAction.setAttribute('style','padding-top:10px;');
	divAction.innerHTML = template;
	// set Property
	actionNameTemplate.setAttribute('id','actionNameTemplate');
	// dom
	action_zone.appendChild(divAction);
	addView();
	document.getElementById('actionName'+STTACTION).focus();
}
function addFunction(){
	STTFUNCTION++;
	
	var input = document.getElementById('template-input-method');
	var public_cb = document.getElementById('template-public-checkbox-method');
	var private_cb = document.getElementById('template-private-checkbox-method');
	var protected_cb = document.getElementById('template-protected-checkbox-method');
	var static_cb = document.getElementById('template-static-checkbox-method');
	// set id and Name	
	input.setAttribute('id','input-method'+STTFUNCTION);;
	input.setAttribute('name','methods['+(STTFUNCTION - 1)+'][]');
	public_cb.setAttribute('id','');
	public_cb.setAttribute('name','methods['+(STTFUNCTION - 1)+'][]');
	private_cb.setAttribute('id','');
	private_cb.setAttribute('name','methods['+(STTFUNCTION - 1)+'][]');
	protected_cb.setAttribute('id','');
	protected_cb.setAttribute('name','methods['+(STTFUNCTION - 1)+'][]');
	static_cb.setAttribute('id','');
	static_cb.setAttribute('name','methods['+(STTFUNCTION - 1)+'][]');
	//get Template
	var template = document.getElementById('template-methods').innerHTML;
	var function_zone = document.getElementById('methods');
	var divMethod = document.createElement('div');
	divMethod.setAttribute('id','method'+STTFUNCTION);
	divMethod.setAttribute('style','padding-top:10px;');
	divMethod.innerHTML = template;
	// reset ID
	input.setAttribute('id','template-input-method');
	public_cb.setAttribute('id','template-public-checkbox-method');
	private_cb.setAttribute('id','template-private-checkbox-method');
	protected_cb.setAttribute('id','template-protected-checkbox-method');
	static_cb.setAttribute('id','template-static-checkbox-method');
	// DOM
	function_zone.appendChild(divMethod);
	document.getElementById('input-method'+STTFUNCTION).focus();
	}
function addProperty(){
	STTPROPERTY++;
	// get Property
	var input = document.getElementById('template-input-property');
	var public_cb = document.getElementById('template-public-checkbox-property');
	var private_cb = document.getElementById('template-private-checkbox-property');
	var protected_cb = document.getElementById('template-protected-checkbox-property');
	// set id and name
	input.setAttribute('id','input-property'+STTPROPERTY);
	input.setAttribute('name','properties['+(STTPROPERTY - 1)+'][]');
	public_cb.setAttribute('id','');
	public_cb.setAttribute('name','properties['+(STTPROPERTY - 1)+'][]');
	private_cb.setAttribute('id','');
	private_cb.setAttribute('name','properties['+(STTPROPERTY - 1)+'][]');
	protected_cb.setAttribute('id','');
	protected_cb.setAttribute('name','properties['+(STTPROPERTY - 1)+'][]');
	// get Template
	var template = document.getElementById('template-properties').innerHTML;
	var property_zone = document.getElementById('properties');
	var divProperty = document.createElement('div');
	divProperty.setAttribute('id','property'+STTPROPERTY);
	divProperty.setAttribute('style','padding-top:10px;');
	divProperty.innerHTML = template;
	
	// reset id 
	input.setAttribute('id','template-input-property');
	public_cb.setAttribute('id','template-public-checkbox-property');
	private_cb.setAttribute('id','template-private-checkbox-property');
	protected_cb.setAttribute('id','template-protected-checkbox-property');
	// DOM
	property_zone.appendChild(divProperty);
	document.getElementById('input-property'+STTPROPERTY).focus();
}
function addView(){
	STTVIEW++;
	// get Property
	var viewNameTemplate = document.getElementById('viewNameTemplate');
	viewNameTemplate.setAttribute('id','viewName'+STTVIEW);
	//create element
	var template = document.getElementById('template-views').innerHTML;
	var view_zone = document.getElementById('views');
	var divView = document.createElement('div');
	divView.setAttribute('id','view'+STTVIEW);
	divView.setAttribute('style','padding-top:10px;');
	divView.innerHTML = template;
	// set Property
	viewNameTemplate.setAttribute('id','viewNameTemplate');
	// dom
	view_zone.appendChild(divView);
	document.getElementById('viewName'+STTVIEW).focus();
}
function addDeny(){
	STTDENY++;
	// get Property
	//alert(denyTemplate_Controller);
	var roleNameTemplate = document.getElementById('role-denyTemplate');
	roleNameTemplate.setAttribute('id','role-deny'+STTDENY);
	var selectTemplate = document.getElementById('select-deny-template');
	selectTemplate.setAttribute('name','deny['+(parseInt(STTDENY)-1)+'][]');
	selectTemplate.setAttribute('id','');
	var denyCount = 'deny'+STTDENY;
	for(var i=1 ; i<denyTemplate_Controller+1;i++){
		var denyTemplate = document.getElementById('denyTemplate-Controller'+i);
		denyTemplate.setAttribute('id',denyCount+'-Controller'+i);
		var denyCheckboxTemplate = document.getElementById('denyTemplate-Controller'+i+'-checkbox');
		denyCheckboxTemplate.setAttribute('id',denyCount+'-Controller'+i+'-checkbox');
		denyCheckboxTemplate.setAttribute('name','deny['+(parseInt(STTDENY)-1)+'][]');
	}
	//create element
	var template = document.getElementById('template-denies').innerHTML;
	var deny_zone = document.getElementById('denies');
	var divDeny = document.createElement('div');
	divDeny.setAttribute('id','deny'+STTDENY);
	divDeny.setAttribute('style','float:left;padding-bottom:10px;');
	divDeny.innerHTML = template;
	// set Property
	roleNameTemplate.setAttribute('id','role-denyTemplate');
	selectTemplate.setAttribute('id','select-deny-template');
	for(var y=1 ; y<denyTemplate_Controller+1;y++){
		var roleNameTemplate = document.getElementById(denyCount+'-Controller'+y);
		roleNameTemplate.setAttribute('id','denyTemplate-Controller'+y);
		var denyCheckboxTemplate = document.getElementById(denyCount+'-Controller'+y+'-checkbox');
		denyCheckboxTemplate.setAttribute('id','denyTemplate-Controller'+y+'-checkbox');
	}
	// dom
	var br1 = document.createElement('div');
	br1.setAttribute('id','denyPad'+STTDENY);
	br1.setAttribute('style','height:40px');
	deny_zone.appendChild(divDeny);
	deny_zone.appendChild(br1);
}
function removeElement(id,name){
	var action_zone = document.getElementById(name);
	var olddiv = document.getElementById(id);
	if(olddiv != null)
	{
		action_zone.removeChild(olddiv);
		if(name == "actions")
		{
			var idView = 'view'+id.substring(6);
			removeElement(idView,'views');
		}
		else if(name == "views")
		{
			var idAction = 'action'+id.substring(4);
			var action = document.getElementById(idAction);
			if(action != null){
				var r=confirm("Xóa action ? ");
				if (r==true){                
					removeElement(idAction,'actions');
				}
			}
		}
		else if(name == "denies")
		{
			var idAction = 'denyPad'+id.substring(4);
			removeElement(idAction,'denies');
		}
	}
}
function setViewName(id,value){
	var view_id = 'viewName'+id.substring(10);
	var viewInput = document.getElementById(view_id);
	if(viewInput != null)
	{
		viewInput.value = value;
	}
}
function selectRole(id){
	var checkbox = document.getElementById(id+'-checkbox');
	if(checkbox.checked === true){
		checkbox.checked=false;
	}else{
		checkbox.checked=true;
	}
}
function nextProperty(e){
	if(e.keyCode == 13){
		addProperty();
	}
}
function nextMethod(e){
	if(e.keyCode == 13){
		addFunction();
	}
}
function nextAction(e){
	if(e.keyCode == 13){
		addAction();
	}
}
function nextView(e){
	if(e.keyCode == 13){
		addView();
	}
}
function getListLayout(value){
	if(value != ""){
		var jxLayout = new Jx();
		jxLayout.setParameter('templateName',value);
		jxLayout.loadInto('layoutController');
		jxLayout.request('/generate/index/getlistlayout','POST');
	}
}
function selectModule(frmObject){
	frmObject.action = '';
	common.submitForm(frmObject,'');
}